package com.whiteape.book.ui.activity;

import android.os.Bundle;
import android.webkit.WebView;

import androidx.appcompat.widget.Toolbar;

import com.whiteape.book.R;
import com.whiteape.book.model.type.WebviewDocType;
import com.whiteape.book.ui.base.BaseActivity;

import butterknife.BindView;

public class WebviewActivity extends BaseActivity {

    public static final String KEY_WEBVIEW_TYPE = "webview_type";

    @BindView(R.id.webview)
    WebView mWebview;

    int webviewType;

    @Override
    protected int getContentId() {
        return R.layout.activity_webview;
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        webviewType = getIntent().getIntExtra(KEY_WEBVIEW_TYPE, 0);

    }

    @Override
    protected void setUpToolbar(Toolbar toolbar) {
        super.setUpToolbar(toolbar);
        if (getSupportActionBar() != null) {

            switch (webviewType){
                case WebviewDocType.WEBVIEW_DOC_TYPE_COMPLAINT:
                    getSupportActionBar().setTitle("版权投诉指引");
                    break;
                case WebviewDocType.WEBVIEW_DOC_TYPE_DISCLAIMER:
                    getSupportActionBar().setTitle("免责声明");
                    break;
                case WebviewDocType.WEBVIEW_DOC_TYPE_PRIVCY:
                    getSupportActionBar().setTitle("隐私政策");
                    break;
                case WebviewDocType.WEBVIEW_DOC_TYPE_SUPPORT:
                    getSupportActionBar().setTitle("技术服务支持");
                    break;
                case WebviewDocType.WEBVIEW_DOC_TYPE_QA:
                    getSupportActionBar().setTitle("常见问题");
                    break;
            }
        }
    }

    @Override
    protected void initView() {
        super.initView();
//        getWindow().getDecorView().setBackgroundColor(WaApp.getInstance().getResources().getColor(R.color.statusBarColor));
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//
//            tvContent.setText(Html.fromHtml(StringUtils.getString(R.string.disclaimer), Html.FROM_HTML_MODE_COMPACT));
//        } else {
//            tvContent.setText(Html.fromHtml(StringUtils.getString(R.string.disclaimer)));
//        }
        switch (webviewType) {
            case WebviewDocType.WEBVIEW_DOC_TYPE_COMPLAINT:
                mWebview.loadUrl("file:///android_asset/complaint.html");
                break;
            case WebviewDocType.WEBVIEW_DOC_TYPE_DISCLAIMER:
                mWebview.loadUrl("file:///android_asset/disclaimer.html");
                break;
            case WebviewDocType.WEBVIEW_DOC_TYPE_PRIVCY:
                mWebview.loadUrl("file:///android_asset/privacy.html");
                break;
            case WebviewDocType.WEBVIEW_DOC_TYPE_SUPPORT:
                mWebview.loadUrl("file:///android_asset/support.html");
                break;
            case WebviewDocType.WEBVIEW_DOC_TYPE_QA:
                mWebview.loadUrl("file:///android_asset/qa.html");
                break;
        }

    }
}
